<template>
  <div class="assessment-edit-plan-container">
    <div class="my-form-container" style="margin:0;width:100%">
      <el-row class="my-form-item" style="height: 20%">
        <el-col :span="12">
          <div class="my-form-item-label">姓 名</div>
          <div class="my-form-item-value">{{ tablelist.name }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">学 号：</div>
          <div class="my-form-item-value">{{ tablelist.studentno }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item" style="height: 20%">
        <el-col :span="12">
          <div class="my-form-item-label">级 次：</div>
          <div class="my-form-item-value"> {{ tablelist.level }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">队 别</div>
          <div class="my-form-item-value"> {{ tablelist.team }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item" style="height: 20%">
        <el-col :span="12">
          <div class="my-form-item-label">专 业：</div>
          <div class="my-form-item-value"> {{ tablelist.major }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">选择缓考课程</div>
          <div class="jf-save " @click="getSelectJob()">
            <button class="jfSave-btn">请选择</button>
          </div>
          <div style="margin-left: 15px;line-height: 170px;" v-for="item in nameArr">
            {{item}}
          </div>
        </el-col>
      </el-row>
      <el-row class="my-form-item" style="height: 10%">
        <el-col :span="24">
          <div class="my-form-item-label">上传材料证明</div>
          <div class="my-form-item-value">
            <div v-if="tablelist.filename" class="fileClass">
              <span>{{ tablelist.filename }}</span>
              <input v-if="type==='修改'" type="file" @change="getFile($event)" class="save"/>
            </div>
            <input v-else type="file" @change="getFile($event)" class="cz-save" style="margin-top: 0px;margin-left: 0px;"/>
          </div>
        </el-col>
      </el-row>
      <el-row class="my-form-item" style="height: 30%;border: none">
        <el-col :span="24">
          <div class="my-form-item-label">缓考原因：</div>
          <div class="my-form-item-value assessment-design">
            <el-input v-model="tablelist.hkdetails" type="textarea" :rows="9" style="width: 969px;" :disabled="type==='查看'" placeholder="请输入内容"></el-input>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog title="选择缓考课程" :visible.sync="showYprDialog" width="983px" style="height:832px" class="szjky">
      <div class="choose-ypr-container">
        <div class="choose-ypr-search-container">
          <span class="title">{{xq}}学期课程：</span>

          <!-- <div class="button-list">
            <div
              class="button-item"
              v-for="(item, index) in courselists"
              :key="index"
              @click="delTag(index)"
              style="width: 124px"
            >
              <img
                class="del-icon"
                src="../../../assets/assessment/approval-del.png"
                alt=""
              />
              <div>{{ item.coursename }}</div>
            </div>
          </div> -->
        </div>
        <div class="choose-ypr-table-container">
          <el-table
            ref="multipleTable"
            :data="yprList"
            style="width: 100% "
            class="xpaas-table-class"
            row-class-name="xpaas-row-class"
            cell-class-name="xpaas-cell-class"
            header-row-class-name="xpaas-header-row-class"
            header-cell-class-name="xpaas-header-cell-class"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              prop=""
              label="选择"
              width="122"
              align="center"
              class-name="" type="selection"

              label-class-name=""
            >
            </el-table-column>
            <el-table-column
              prop="department"
              label="系"
              width="122"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="teachingandresearchsection" label="研究室" width="122" align="center">
            </el-table-column>
            <el-table-column
              prop="coursenumber"
              label="课程编号"
              width="122"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="coursename" label="课程名称" width="122" align="center">
            </el-table-column>
            <el-table-column prop="teachingfaculty" label="课程教员" width="122" align="center">
            </el-table-column>
            <el-table-column prop="exadate" label="考试日期" width="122" align="center">
            </el-table-column>
            <el-table-column prop="exaschedule" label="节次" align="center">
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="green" @click="addCourse">确 定</button>
      </span>
    </el-dialog>
    <div class="button-group" >
      <div class="" @click="getsubmit('保存')">保存</div>
      <div class="" @click="getsubmit('提交')">保存并提交</div>
    </div>
  </div>

</template>

<script>
import {createDId, detail, getsave, getUpload, hkkcList, submit,getCurrentOne} from "@/api/examination/approvalDelayedExam";
import { getDept } from "@/api/system/dept"
import { querysppecltyId } from "@/api/classHoursAddList/addList"

export default {
  data() {
    return {
      showYprDialog: false,
      searchNameList: [],
      courselists: [],
      yprList: [],
      fileName: '',
      design: '',
      xq: this.$route.query.term,
      tablelist: {
        name: "",
        studentno: "",
        level: "",
        team: "",
        major: "",
        courselists: [],
        hkdetails: ''

      },
      courselistsList: [],
      nameArr:[],
      xqList: [],
      type: ''
    }
  },
  mounted() {
    // this.getdetail()
    // this.getCreateDId(this.tablelist)
    this.getCurrentOne()
  },
  methods: {
    getCurrentOne() {
      return new Promise(() => {
        getCurrentOne().then(res => {
          let data = res.data.data;
          if(data.studentDui && data.studentDui != ''){
            getDept(data.studentDui).then(result=>{
              if(result.data.code == 200){
                this.tablelist.team = result.data.data.deptName
              }
            })
          } else {
            this.tablelist.team = ''
          }
          if(data.specialtyClassId && data.specialtyClassId != ''){
            querysppecltyId(data.specialtyClassId).then(result=>{
              if(result.data.code == 200){
                this.tablelist.level = result.data.data.year
              }
            })
          } else {
            this.tablelist.level = ''
          }
          this.tablelist = {
            name: data.studentName,
            studentno: data.studentCode,
            level: this.tablelist.level,
            team:this.tablelist.team,
            major: data.specialtyClassName,
            courselistsDto: [],
            hkdetails: ''
          }
          this.getCreateDId(this.tablelist)
        })
      })
    },
    getCreateDId(obj) {
      return new Promise(() => {
        createDId(obj).then(res => {
          this.tablelist.id = res.data.data

        })
      })
    },
    getsubmit(type) {
      let obj = this.tablelist
      if (obj.courselistsDto.length <= 0) {
        this.$message({
          showClose: true,
          message: "缓考课程不能为空",
          type: "error",
        });
        return
      }
      if (!obj.fileName) {
        this.$message({
          showClose: true,
          message: "上传材料证明未上传",
          type: "error",
        });
        return
      }
      if (!obj.hkdetails) {
        this.$message({
          showClose: true,
          message: "缓考原因未填写",
          type: "error",
        });
        return
      }
      this.tablelist.xueqi = this.$route.query.term;
      let message
      let el = this
      if (type === '保存') {
        this.tablelist.status = -1
        message = '保存成功'
      } else if (type === '提交') {
        message = '保存并提交成功'
        this.tablelist.status = 0
      }
      obj.planid = obj.courselistsDto[0].courseid
      return new Promise(() => {
        getsave(obj).then(res => {
          if (res.data.code === 200) {
            el.$message({
              showClose: true,
              message: message,
              type: "success",
            });
            let pathname = '/' + window.location.pathname.split('/')[1]
            this.$router.push(pathname + "/approvalDelayedExam/approvalDelayedExam");
          }
        })
      })
    },
    getFile(event) {
      let file = event.target.files;
      this.tablelist.fileName = file[0].name
      // this.fileName=file
      let form = new FormData();
      let id = this.tablelist.id
      form.append("file", file[0]);
      form.append("id", id);
      let el = this
      return new Promise(() => {
        getUpload(form).then(res => {
          if (res.data.code === 200) {
            this.tablelist.fileName = file[0].name
            // this.getdetail()
            el.$message({
              showClose: true,
              message: "上传成功",
              type: "success",
            });
          } else {
            el.$message({
              showClose: true,
              message: "上传失败，请重新上传",
              type: "error",
            });
          }
        })
      })
    },
    delTag(index) {
      let el = this

      // this.$refs.multipleTable.clearSelection(this.searchNameList[index]);
      el.$nextTick(() => {
        el.$refs.multipleTable.toggleRowSelection(
          el.yprList.find(item => {
            return this.courselists[index].id == item.id;
            }
          ), false);

      })
    },
    getSelectJob() {
      return new Promise(() => {
        let el = this
        hkkcList(this.xq).then(res => {
          if (res.data.code === 200) {
            this.yprList = res.data.data
            this.showYprDialog = true
            el.$nextTick(() => {
              el.courselistsList.forEach(row => {
                el.$refs.multipleTable.toggleRowSelection(
                  this.yprList.find(item => {
                      return row == item.id;
                    }
                  ), true);
              });
            })
          }
        })
      })

    },
    getdetail() {
      let obj = {
        id: this.tablelist.id
      }
      return new Promise(() => {
        detail(obj).then(res => {
          if (res.data.code === 200) {
            let arr = []
            this.tablelist = res.data.data
            this.tablelist.filename = this.tablelist.filepath.split(';')[1];

            let courselists = this.tablelist.courselists
            for (let i = 0; i < courselists.length; i++) {
              arr.push(courselists[i].matchid)
            }
            this.courselistsList = arr
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.courselists = val
      this.tablelist.courselistsDto = val
    },
    //选择缓考课程点击确定
    addCourse(){
      if(this.tablelist.courselistsDto.length > 1){
        this.$message({
          type:'info',
          message:'只允许选择一门课程!'
        })
        return
      }
      let arr=[]
      let nameArr = [];
      if(this.tablelist.courselistsDto.length > 0){
        for (let i = 0; i < this.tablelist.courselistsDto.length; i++) {
          this.tablelist.courselistsDto[i].matchid = this.tablelist.courselistsDto[i].id
          arr.push(this.tablelist.courselistsDto[i].id)
          nameArr.push(this.tablelist.courselistsDto[i].coursename)
        }
        if (arr.length) {
          this.courselistsList = arr
          this.nameArr = nameArr
        }
      } else {
        this.nameArr = []
      }
      this.showYprDialog = false;
    }
  }
};
</script>
<style lang="less" scoped>
.jfSave-btn{
  width:90px;
  height:30px;
  color: #02C86C;
  border: 1px solid #02C86C;
  background: #F1FFF8;
  border-radius: 6px;
}
.choose-ypr-container {
  width: 100%;
  margin: 0px auto;

  .choose-ypr-search-container {
    .el-input--prefix .el-input__inner {
      padding-left: 30px;
    }

    .el-input__inner {
      &::placeholder {
        color: #b8b8b8;
      }

      &::-webkit-input-placeholder {
        /* WebKit browsers 适配谷歌 */
        color: #b8b8b8;
      }

      &:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 适配火狐 */
        color: #b8b8b8;
      }

      &::-moz-placeholder {
        /* Mozilla Firefox 19+ 适配火狐 */
        color: #b8b8b8;
      }

      &:-ms-input-placeholder {
        /* Internet Explorer 10+  适配ie*/
        color: #b8b8b8;
      }
    }

    display: flex;
    flex-direction: row;
    align-items: center;

    .title {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
      margin-right: 5px;
    }

    .search-button {
      width: 77px;
      height: 28px;
      line-height: 28px;
      background: #f1f8fe;
      border: 1px solid #51aef6;
      border-radius: 6px;
      cursor: pointer;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;

      > span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #51aef6;
      }

      > img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }
    }

    .button-list {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-left: 21px;

      .button-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 69px;
        height: 27px;
        line-height: 27px;
        border: 1px solid #004ca7;
        border-radius: 4px;
        margin-right: 10px;
        text-align: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #004ca7;

        .del-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 12px;
          height: 12px;
          padding: 2px;
        }
      }
    }
  }

  .choose-ypr-container .choose-ypr-table-container .el-table__header th {
    padding: 0;
    height: 57px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  /deep/  .el-table .cell{

    color: #004ca7;
  }
  .choose-ypr-table-container {
    margin-top: 30px;

    .el-table td,
    .el-table th.is-leaf,
    .el-table--border,
    .el-table--group {
      border-color: #c7d7eb;
    }


    .el-table__header tr,
    .el-table__header th {
      padding: 0;
      height: 57px;
      background-color: #edf2f9;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;

    }

    .el-table__body tr,
    .el-table__body td {
      padding: 0;
      height: 51px;
    }

    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      border-radius: 9px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}

.assessment-container {
  .el-dialog__body {
    height: 251px;
  }

  .el-dialog__footer {
    padding: 10px 20px 45px;
  }

  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }

  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }

  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }

  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }

  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }

  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }

  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}

.cz-save {
  box-sizing: border-box;
  line-height: 44px;
  border-radius: 4px;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  text-align: center;
  margin-top: 70px;
  margin-left: 40px;
  display: flex;
  flex-direction: row;
  cursor: pointer;
  align-content: center;
  justify-content: center;
  align-items: center;

}

.jf-save {
  display: flex;
  align-items: center;
  margin-left: 48px;
}

.fileClass {
  position: relative;
  cursor: pointer;

  .save {
    width: 120px;
    height: 50px;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    color: #fff;
    background: #303133;
  }
}


.my-form-item-value {
  font-size: 16px;
  color: #004CA7;
  height: 100%;
  flex: 1;
  line-height: 60px;
  padding-left: 38px;
  display: flex;
  align-items: center;
}

.assessment-edit-plan-container {
  .assessment-design {
    .el-textarea__inner {
      resize: none;
      font-size: 16px;
      color: rgba(0, 76, 167, 1);
    }
  }
}
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  margin: 15px 0;
  > ::v-deep div.el-table__header-wrapper {
    > table.el-table__header {
      > thead {
        > tr.xpaas-header-row-class {
          padding: 0;
          height: 76px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          > th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  > ::v-deep div.el-table__body-wrapper {
    > table.el-table__body {
      > tbody {
        > tr.xpaas-row-class {
          > td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          > td.xpaas-cell-class {
            height: 76px;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            > div.cell {
              font-weight: normal;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
</style>
<style scoped lang="less">
.assessment-edit-plan-container {
  .assessment-design {
    padding: 25px 38px !important;
  }

  .button-group {
    cursor: pointer;
    text-align: center;
    margin-top: 25px;
    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;

      &:nth-child(1) {
        color: #F3B815;
        border: 1px solid #F3B815;
        background: #FFF6EF;
        margin-right: 139px;
      }

      &:nth-child(2) {
        color: #02C86C;
        border: 1px solid #02C86C;
        background: #F1FFF8;
      }
    }
  }
}
</style>
